﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;


using System.Data;
using System.Text;
using Maticsoft.DBUtility;
using Utils;
using System.Collections.Specialized;
using Maticsoft.Model;

public partial class WebPage_ajaxPage_manage_ajax_dialog_orderview : SystemBBasePage
{
    // Fields

    public Maticsoft.BLL.Category catebll = new Maticsoft.BLL.Category();
    public Maticsoft.BLL.Coupon couponbll = new Maticsoft.BLL.Coupon();
    private Maticsoft.BLL.Coupon couponBll = new Maticsoft.BLL.Coupon();
    public Maticsoft.BLL.Coupon couponmodel = new Maticsoft.BLL.Coupon();

    public Maticsoft.BLL.orderdetail detailbll = new Maticsoft.BLL.orderdetail();
    public List<orderdetail> detaillist = new List<orderdetail>();


    public Order item = new Order();
    public Maticsoft.BLL.Order mbod = new Maticsoft.BLL.Order();

    protected NameValueCollection orderarr = new NameValueCollection();
    public string pagenum = "";

    public Maticsoft.BLL.Team team = new Maticsoft.BLL.Team();
    protected NameValueCollection teamarr = new NameValueCollection();
    public Team teamodel = new Team();

    public string txt = "";
    protected NameValueCollection userarr = new NameValueCollection();
    public Maticsoft.BLL.UserInfo userInfo = new Maticsoft.BLL.UserInfo();

    public string wuliu = "";

    // Methods
    private void getContent(int id)
    {
        try
        {
            int num2;
            string txt;
            this.item = this.mbod.GetModel(id);
            this.orderarr = Helper.GetObjectProtery(this.item);
            DataSet set = new DataSet();
            foreach (UserInfo info in this.userInfo.GetModelList("Id=" + this.item.User_id))
            {
                this.username.InnerText = info.Username;
                this.mobile.InnerText = info.Mobile;
                this.email.InnerText = info.Email;
                this.qq.InnerText = info.Qq;
                this.msn.InnerText = info.MSN;
                this.userarr = Helper.GetObjectProtery(info);
                this.mobileName.InnerText = info.Mobile;
                this.mobileName1.InnerText = info.Mobile;
            }
            foreach (Team team in this.team.GetModelList("Id=" + this.item.Team_id))
            {
                this.title.InnerText = team.Title;
                this.teamarr = Helper.GetObjectProtery(team);
            }
            this.teamarr = Helper.GetObjectProtery(this.team.GetModel(this.item.Team_id));
            Maticsoft.BLL.Category category = new Maticsoft.BLL.Category();
            string str = " Zone='express' and id=" + this.orderarr["Express_id"];
            DataSet list = category.GetList(" Zone='express' and id=" + this.orderarr["Express_id"]);
            if (list.Tables[0].Rows.Count > 0)
            {
                this.wuliu = "<tr><td><b>物流信息：</b></td><td style='color:red'>" + Maticsoft.BLL.Order.Getxml(list.Tables[0].Rows[0]["Ename"].ToString(), this.orderarr["Express_no"], "1") + "</td></tr>";
            }
            if (this.team.GetModel(this.item.Team_id) != null)
            {
                this.title.InnerText = this.team.GetModel(this.item.Team_id).Title;
            }
            else
            {
                this.detaillist = this.detailbll.Searchorderdetail(this.item.Id);
                int num = 0;
                foreach (orderdetail orderdetail in this.detaillist)
                {
                    num++;
                    this.title.InnerHtml = this.title.InnerHtml + num + ":";
                    this.title.InnerHtml = this.title.InnerHtml + ((this.team.GetModel(Convert.ToInt32(orderdetail.Teamid)) == null) ? "" : this.team.GetModel(Convert.ToInt32(orderdetail.Teamid)).Title);
                    object innerHtml = this.title.InnerHtml;
                    this.title.InnerHtml = string.Concat(new object[] { innerHtml, "<font style='color:red'>(", orderdetail.Num, "件)</font>" });
                    this.title.InnerHtml = this.title.InnerHtml + "<br>";
                }
            }
            this.quantity.InnerText = this.item.Quantity.ToString();
            if (this.item.State == "pay")
            {
                this.state.InnerText = "已支付";
            }
            else if (this.item.State == "unpay")
            {
                this.state.InnerText = "未支付";
            }
            this.pay_id.InnerText = this.item.Pay_id;
            this.credit.InnerText = "余额付款:" + this.item.Credit.ToString();
            this.money.InnerText = this.item.Money.ToString();
            this.card.InnerText = this.item.Card.ToString();
            string service = this.item.Service;
            if (service != null)
            {
                if (!(service == "yeepay"))
                {
                    if (service == "tenpay")
                    {
                        goto Label_0578;
                    }
                    if (service == "chinabank")
                    {
                        goto Label_058B;
                    }
                    if (service == "credit")
                    {
                        goto Label_059E;
                    }
                    if (service == "alipay")
                    {
                        goto Label_05B1;
                    }
                }
                else
                {
                    this.service.InnerText = "易宝";
                }
            }
            goto Label_05C6;
        Label_0578:
            this.service.InnerText = "财付通";
            goto Label_05C6;
        Label_058B:
            this.service.InnerText = "网银在线";
            goto Label_05C6;
        Label_059E:
            this.service.InnerText = "余额付款";
            goto Label_05C6;
        Label_05B1:
            this.service.InnerText = "支付宝";
        Label_05C6:
            this.date.InnerText = this.item.Create_time.ToString();
            this.remark.InnerText = this.item.Remark;
            this.realname.InnerText = this.item.Realname;
            this.address.InnerText = this.item.Address;
            this.realname1.InnerText = this.item.Realname;
            this.address1.InnerText = this.item.Address;
            set = this.catebll.GetList("Zone='express'");
            this.teamodel = this.team.GetModel(this.item.Team_id);
            if (this.teamodel != null)
            {
                if (this.teamodel.Delivery == "express")
                {
                    this.express.InnerHtml = "<select id='express_id' name='express_id'>";
                    this.express.InnerHtml = this.express.InnerHtml + "<option value='0'>请选择快递</option>";
                    for (num2 = 0; num2 < set.Tables[0].Rows.Count; num2++)
                    {
                        if (this.item.Express_id.ToString() == set.Tables[0].Rows[num2]["Id"].ToString())
                        {
                            txt = this.express.InnerHtml;
                            this.express.InnerHtml = txt + "<option value='" + set.Tables[0].Rows[num2]["Id"].ToString() + "' selected='selected'>" + set.Tables[0].Rows[num2]["Name"].ToString() + "</option>";
                        }
                        else
                        {
                            txt = this.express.InnerHtml;
                            this.express.InnerHtml = txt + "<option value='" + set.Tables[0].Rows[num2]["Id"].ToString() + "'>" + set.Tables[0].Rows[num2]["Name"].ToString() + "</option>";
                        }
                    }
                    this.express.InnerHtml = this.express.InnerHtml + "</select>";
                }
            }
            else
            {
                this.txt = this.txt + "<select id='express_id' name='express_id'>";
                this.txt = this.txt + "<option value='0'>请选择快递</option>";
                for (num2 = 0; num2 < set.Tables[0].Rows.Count; num2++)
                {
                    if (this.item.Express_id.ToString() == set.Tables[0].Rows[num2]["Id"].ToString())
                    {
                        txt = this.txt;
                        this.txt = txt + "<option value='" + set.Tables[0].Rows[num2]["Id"].ToString() + "' selected='selected'>" + set.Tables[0].Rows[num2]["Name"].ToString() + "</option>";
                    }
                    else
                    {
                        txt = this.txt;
                        this.txt = txt + "<option value='" + set.Tables[0].Rows[num2]["Id"].ToString() + "'>" + set.Tables[0].Rows[num2]["Name"].ToString() + "</option>";
                    }
                }
                this.txt = this.txt + "</select>";
            }
            this.express_no.Value = this.item.Express_no;
            this.express_no1.Value = this.item.Express_no;
            this.optionfund.InnerHtml = "<select name='refund' id='option_refund'>";
            this.optionfund.InnerHtml = this.optionfund.InnerHtml + "<option value='0'>请选择退款方式</option>";
            this.optionfund.InnerHtml = this.optionfund.InnerHtml + "<option value='1'>退款到账户余额</option>";
            this.optionfund.InnerHtml = this.optionfund.InnerHtml + "</select>";
        }
        catch (Exception)
        {
        }
    }

    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
        if (!this.Page.IsPostBack && (base.Request.QueryString["orderview"] != null))
        {
            this.getContent(int.Parse(base.Request.QueryString["orderview"].ToString()));
            this.hid.Value = base.Request.QueryString["orderview"].ToString();
        }
        if (base.Request["pagenum"] != null)
        {
            this.pagenum = base.Request["pagenum"];
        }
        if (base.Request.Form["buttontype"] == "修改")
        {
            this.updateorder();
        }
        if (base.Request.Form["buttontype"] == "确定")
        {
            this.updatestate();
        }
    }

    public void updateorder()
    {
        string str = this.hid.Value;
        this.item = this.mbod.GetModel(Convert.ToInt32(this.hid.Value));
        string str2 = base.Request["express_id"];
        string str3 = base.Request["express_no"];
        if (base.Request["express_id"] == "0")
        {
            base.SetSuccess("请选择快递");
            base.Response.Redirect(this.Page.Request.UrlReferrer.AbsoluteUri.Split(new char[] { '?' })[0] + "?pagenum=" + this.pagenum);
            base.Response.End();
        }
        else
        {
            switch (str3)
            {
                case null:
                case "":
                    str3 = base.Request["express_no1"];
                    break;
            }
            this.item.Express_id = Convert.ToInt32(str2);
            this.item.Express_no = str3;
            this.item.Express = "Y";
            this.mbod.Update(this.item);
            base.SetSuccess("修改快递信息成功");
            base.Response.Redirect(this.Page.Request.UrlReferrer.AbsoluteUri.Split(new char[] { '?' })[0] + "?pagenum=" + this.pagenum);
            base.Response.End();
        }
    }

    public void updatestate()
    {
        string str;
        RefundType @int = (RefundType)Helper.GetInt(base.Request["refund"], 0);
        string errtext = ActionHelper.Mananger_RefundMent(Helper.GetInt(this.hid.Value, 0), base.AsUser.Id, @int, out str);
        if (errtext == string.Empty)
        {
            base.SetSuccess(str);
        }
        else
        {
            this.SetError(errtext);
        }
        base.Response.Redirect(this.Page.Request.UrlReferrer.AbsoluteUri);
        base.Response.End();
    }

}